{extend name="base" /}
{block name="content"}
<script src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>积分订单管理</span>
            <span class="icon-angle-right"></span>
            <span>积分订单列表</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <table class="m-table">
                <tr>
                    <th>
                        <div class="m-options cf">
                            <div class="m-search fr">
                                <form action="" class="layui-form" id="searchForm">
                                    <label for="">订单状态</label>
                                    <div class="lay-select m-select-tiny">
                                        <select name="order_status_id">
                                            <option value="0"{if condition="$order_status_id eq 0"} selected{/if}>全部订单</option>
                                            <option value="1"{if condition="$order_status_id eq 1"} selected{/if}>已取消</option>
                                            <option value="2"{if condition="$order_status_id eq 2"} selected{/if}>未付款</option>
                                            <option value="3"{if condition="$order_status_id eq 3"} selected{/if}>已付款</option>
                                            <option value="4"{if condition="$order_status_id eq 4"} selected{/if}>待发货</option>
                                            <option value="5"{if condition="$order_status_id eq 5"} selected{/if}>等收货</option>
                                            <option value="6"{if condition="$order_status_id eq 6"} selected{/if}>已完成</option>
                                        </select>
                                    </div>
                                    <label for="keywords">下单会员</label>
                                    <input type="text" name="keywords" id="keywords" class="u-ipt u-ipt-def" placeholder="请输入要会员" value="{$keywords}" />
                                    <label for="">下单时间</label>
                                    <input type="text" name="start_time" class="u-ipt u-ipt-small" placeholder="开始时间" value="{$startTime ?: ''}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly />
                                    <span>-</span>
                                    <input type="text" name="end_time" class="u-ipt u-ipt-small" placeholder="结束时间" value="{$endTime ?: ''}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly />
                                    <input type="submit" class="u-btn u-search" value="查看" />
                                    <input type="button" class="u-btn u-export" value="导出" />
                                </form>
                            </div>
                        </div>
                    </th>
                </tr>
            </table>
            <form class="layui-form m-list-form">
                <table class="m-table mt-10">
                    <tbody class="datas">
                        <tr>
                        	<th width="5%" style="text-align: center;">选择</th>
                            <th width="5%">ID</th>
                            <th width="10%">订单编号</th>
                            <th width="10%">下单会员</th>
                            <th width="10%">收货人</th>
                            <th width="10%">订单所需积分</th>
                            <th width="10%">支付积分</th>
                            <th width="10%">下单时间</th>
                            <th width="15%">订单状态</th>
                            <th width="10%">操作</th>
                        </tr>
                        {foreach name="data" item="v"}
                        <tr>
                        	<td align="center"><input type="checkbox" name="id[]" class="u-id" value="{$v.id}" lay-skin="primary" /></td>
                            <td>{$v.id}</td>
                            <td>{$v.order_no}</td>
                            <td>{$v.username}</td>
                            <td>{$v.receiver_name}</td>
                            <td>{$v.pay_amount}</td>
                            <td>{$v.points}</td>
                            <td>{$v.create_time_date}</td>
                            <td>{$v.order_status_txt}</td>
                            <td class="m-opt"><a href="{:url('add', ['id' => $v.id])}" title="查看详情"><i class="icon-pencil"></i></a></td>
                        </tr>
                        {/foreach}
                        <tr>
                             <td align="center"><input type="checkbox" value="1" lay-skin="primary" lay-filter="select_ids" /></td>
                            <td colspan="10" class="m-options"><button class="u-btn u-batch-del"><i class="icon-trash"></i>批量删除</button></td>
                        </tr>
                    </tbody>
                </table>
            </form>
            {include file="public:page" /}
        </div>
    </div>
</div>
{/block}
{block name="extrajs"}
{include file="laypage" /}
<script>
    $(function(){
        layui.use('layer', function(){
            $('.u-export').click(function(){
                $('#searchForm').attr('action', '{:url("export")}');
                $('#searchForm').submit();
            })
            
            
            
            $('body').on('keyup', '.u-nick', function(){
                var $that = $(this);
                $.post('{:url("/manage/members/search")}', {nickname: $(this).val()}, function(ret){
                    if (ret) {
                        var html = '';
                        if (ret.status == 0) {
                            if (ret.data.length > 0) {
                                html += '<ul>';
                                for (var i = 0; i < ret.data.length; i++) {
                                    html += '<li><a class="u-nick-item" data-userid="'+ret.data[i].id+'">'+ret.data[i].nickname+'</a></li>';
                                }
                                html += '</ul>';
                            } else {
                                html = '<h3>暂无搜索结果</h3>';
                            }
                        } else {
                            html = '<h3>暂无搜索结果</h3>';
                        }
                        $that.next().next().html(html);
                        $that.next().next().show();
                    }
                }, 'json');
            });
            
            $('body').on('click', '.u-nick-item', function(){
                $(this).parent().parent().parent().prev().attr('data-userid', $(this).attr('data-userid'));
                $(this).parent().parent().parent().prev().prev().val($(this).text());
                $(this).parent().parent().parent().hide();
            });
            
            $('body').on('click', '#j_allot', function(){
                var id     = $(this).attr('data-id');
                var userid = $(this).attr('data-userid');
                $.post('{:url("allot")}', {id: id, userid: userid}, function(ret){
                    if (ret.status == 0) {
                        dialog.success(ret.message, function(){
                            layer.closeAll();
                            window.location.reload();
                        });
                    } else {
                        dialog.error(ret.message);
                    }
                }, 'json');
            });
        })
    })
</script>
{/block}